/* libfake437 - a library for the rendering of code page 437 `graphics'
 * Copyright (C) 2008, 2009, 2010 Jack Kelly <endgame.dos@gmail.com>
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef FAKE437_DISPLAY_HPP
#define FAKE437_DISPLAY_HPP

namespace fake437 {
  class DisplayLayer {
    friend class Display;
  public:
    DisplayLayer(int left, int top, int width, int height);
    /* Does not incrememnt the reference count, so implicit conversion
       from the result of Display::get_layer etc. doesn't generate
       spurious f437_display_layer_ref's. */
    /* Only shares the reference. */
    DisplayLayer(const DisplayLayer& other);
    DisplayLayer(F437DisplayLayer* layer);
    ~DisplayLayer(void);
    /* Only shares the reference. */
    DisplayLayer& operator =(const DisplayLayer& other);
    F437DisplayCell& get_cell(int x, int y);
    int get_left(void) const;
    int get_top(void) const;
    void set_left(int left);
    void set_top(int top);
  private:
    F437DisplayLayer* layer;
  };

  class Display {
  public:
    Display(SDL_Surface* surface, const F437Font* font);
    ~Display(void);

    void insert_layer(F437DisplayLayer* layer, int n);
    void insert_layer(DisplayLayer& layer, int n);
    F437DisplayLayer* get_layer(int n);
    void remove_layer(int n);

    void swap_layers(int n, int m);

    void push_layer(F437DisplayLayer* layer);
    void push_layer(DisplayLayer& layer);
    F437DisplayLayer* peek_layer(void);
    void pop_layer(void);

    void draw(void);

    SDL_Surface* get_surface(void);

    /* Width/height in characters. */
    int get_width(void) const;
    int get_height(void) const;
  private:
    F437Display *display;
    /* Disallow copy and assign. */
    Display(const Display&);
    void operator =(const Display&);
  };
}

#endif
